package com.py.credit.clean.code;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class SwdjhCheck {
	
	/**
	 * 税务登记号校验（空则不校验）
	 * 
	 * 	15位=6位税务区划+企业编码
		17位=15位身份证+2编码
		18位=身份证
		20位=18位身份证+2编码
	 */
	public boolean run(String data, String extend){
		if(StringUtils.isEmpty(data)){
			return true;
		}
		
		IdcardValidator check = null;
		Pattern pattern = null;
		
		int length = data.length();
		if(length == 7 || length == 9 || length == 15 || length == 16){
			pattern = Pattern.compile("^[0-9A-Z]{7,16}$");
			Matcher matcher = pattern.matcher(data);
			if (matcher.matches()) {
				return true;
			}
		}else if(length == 18){
			check = new IdcardValidator();
			if(check.run(data, null)){
				return true;
			}
		}else if(length == 20){
			check = new IdcardValidator();
			if(check.run(data.substring(0, 18), null)){
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		String data = "91320205MA1MGM890C";
		
		SwdjhCheck check = new SwdjhCheck();
		System.out.println(check.run(data, ""));
	}

}
